﻿/// <reference path="../scripts/jquery-1.11.2.min.js" />
/// <reference path="../scripts/bootstrap.min.js" />
var pi = 1;
if (typeof ($) != "undefined" && $) {
    //验证用户
    CheckUser();
    $(document).ready(onReady);
}

function onReady() {
    var ua = navigator.userAgent.toLowerCase();
    var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);

    $.ajax({
        type: "get",
        url: "api/member.ashx?ac=account&k=" + Math.random(),
        beforeSend: function () {
            $('#loadingToast').show();
        },
        error: function () {
            showToast("数据加载失败");
        },
        success: function (data) {
            if (data != null && data != '') {
                var m = eval("(" + data + ")");
                $("#money").html(toDecimal2(m.account));
//                if (Number(m.account) > 0) {
//                    $("#btncash").removeAttr('disabled');
//                    $("#btncash").removeClass('btn-disabled');
//                    $("#btncash").addClass('btn-yellow');
//                }
            }
            getlist();
        },
        complete: function () {
            $('#loadingToast').hide();
        }
    });

    $("#btncash").click(function () {
        alert('暂未开通提现功能');
        //window.location.href = 'cpbuy.html';
    });
    $("#load").click(function () {
        pi = Number(pi) + 1;
        getlist();
    });
}

function getlist() {
    var data = { ps: 10, pi: pi };
    $.ajax({
        url: "api/member.ashx?ac=accountlist&k=" + Math.random(),
        data: data,
        type: 'GET',
        beforeSend: function () {
            $("#load").html('正在加载');
        },
        error: function () {
            $("#load").html('加载失败');
        },
        success: function (data) {
            var obj = eval("(" + data + ")");
            var list = eval("(" + obj.list + ")");
            for (var m = 0; m < list.length; m++) {
                var o = list[m];
                var htm = '<div class="weui_cell">';
                htm += '<div class="weui_cell_bd weui_cell_primary">' + o.OpType + '<br />' + o.Date + '</div>';
                htm += '<div class="weui_cell_no">' + o.Money + '</div>';
                htm += '</div>';
                $("#aclist").append(htm);
            }


            if (Number(pi) < Number(obj.tp)) {
                $("#load").html('加载更多');
                $("#load").removeClass('none');
            }
            else {
                $("#load").addClass('none');
            }
        }
    });
}